//mapgen(width,height)



//spawn cells
g = 1

i = 1
j = 0
k = 1



repeat(((argument1-64)/32)*((argument0-64)/32)){
if j = (argument0-64)/32{
k++
j=0
i = 1
}

with instance_create(i*32 + 16 ,k*32+16,ocell){num = other.g}

j++
i++



g++
}




//dig wall to make maze
with ocell{







//--------------------------------------------------

//check sides



//loops until dun
while true{
//var xx and yy
xx = x
yy = y
//check vertically or horizontally from current tile
check = choose("v","h")
bakfor = choose(-1,1)
if check = "v"{
yy = y+32*bakfor
}else{
xx = x+32*bakfor
}

//make sure cell is there first of all
if instance_position(xx,yy,ocell) != noone{

inst = instance_position(xx,yy,ocell)


//if not visited
if inst.visited = false{
inst.visited = true

//set inst to wall
inst = instance_position((x+16*!(xx = x)*bakfor),(y+16*!(yy = y)*bakfor),ogenwall)
//delete wall
if inst !=noone{

with inst {instance_destroy()}
}


//break loop becuz dun

break
}else{
//else do nothing for now -- WIP
break

}


}


}

}

//---------------








//make corner walls


i = 1
j = 0
k = 1
repeat(((argument1-32)/32)*((argument0-32)/32)){
if j = (argument0-32)/32{
k++
j=0
i = 1
}

instance_create(i*32,k*32,ogenwall)

j++
i++




}


//spawn player
xx = irandom_range(16,argument0)
yy = irandom_range(16,argument1)
instance_create((xx)-(xx mod 16),(yy)-(yy mod 16),oplayer)
with instance_position(xx,yy,ogenwall){instance_destroy()}
//destroy_surrounding()
//global.flag10++


//spawn exit
//with ocell {if irandom_range(1,((argument1-64)/32)*((argument0-64)/32)) = num{
xx = irandom_range(16,argument0)
yy = irandom_range(16,argument1)
instance_create((xx)-(xx mod 16),(yy)-(yy mod 16),oexit)
with instance_position(xx,yy,ogenwall){instance_destroy()}



